package com.cl.generator;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Description mybatis-plus逆向工程
 * @Author cr7
 * @Date 2022/3/13
 * @Version V1.0
 */
public class MPG {

    public static void main(String[] args) {
        List<String> tables = new ArrayList<>();
        tables.add("t_admin");
        tables.add("t_admin_role");
        tables.add("t_classroom");
        tables.add("t_collect");
        tables.add("t_deliver_resume");
        tables.add("t_enterprise");
        tables.add("t_hr");
        tables.add("t_menu");
        tables.add("t_menu_role");
        tables.add("t_nation");
        tables.add("t_political_face");
        tables.add("t_position");
        tables.add("t_preaching_sessions");
        tables.add("t_recruit");
        tables.add("t_resume");
        tables.add("t_role");
        tables.add("t_student");
        tables.add("t_type");
        tables.add("t_notice");
        tables.add("t_university");

        FastAutoGenerator.create("jdbc:mysql://localhost:3306/recruit?useUnicode=true&characterEncoding=UTF8&serverTimezone=Asia/Shanghai", "root", "021206")
                .globalConfig(builder -> {
                    builder.author("cl")               //作者
                            .outputDir(System.getProperty("user.dir") + "\\src\\main\\java")    //输出路径(写到java目录)
                            .enableSwagger()           //开启swagger
                            .commentDate("yyyy-MM-dd");

                })
                .packageConfig(builder -> {
                    builder.parent("")
                            //.moduleName("c")
                            .entity("model")
                            .service("service")
                            .serviceImpl("service.impl")
                            .controller("com.cl.web.controller")
                            .mapper("mapper")
                            .xml("mapper")
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, System.getProperty("user.dir") + "\\src\\main\\resources\\mapper"));
                })
                .strategyConfig(builder -> {
                    builder.addInclude(tables)
                            .addTablePrefix("t_")
                            .serviceBuilder()
                            .formatServiceFileName("%sService")
                            .formatServiceImplFileName("%sServiceImpl")
                            .entityBuilder()
                            .enableLombok()
                            .logicDeleteColumnName("deleted")
                            .enableTableFieldAnnotation()
                            .controllerBuilder()
                            .formatFileName("%sController")
                            .enableRestStyle()
                            .mapperBuilder()
                            .enableBaseColumnList()
                            .enableBaseResultMap()  //生成通用的resultMap
                            .superClass(BaseMapper.class)
                            .formatMapperFileName("%sMapper")
                            .formatXmlFileName("%sMapper");
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
